package com.docker.manege.container;

import com.docker.core.constant.APPIDConstant;
import com.docker.core.mvc.APPID;
import com.docker.core.mvc.Remark;
import com.docker.core.mvc.controller.BaseAPIController;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Okv;

/**
 * @Author ldl
 * @Create 2020/12/02 002 14:56
 */
@Remark("容器管理")
@APPID(APPIDConstant.dum_web)
@Before(ContainerValidator.class)
public class ContainerController extends BaseAPIController {

    @Inject
    private ContainerService containerService;

    @Remark("获取容器列表")
    public void list() {
        renderAPISuccess(containerService.list(getClientKey(), getPara("container_id"), getPara("container_name")));
    }

    @Remark("启动容器")
    public void start() {
        renderAPI(containerService.start(getClientKey(), getPara("container_id")));
    }

    @Remark("停止容器")
    public void stop() {
        renderAPI(containerService.stop(getClientKey(), getPara("container_id")));
    }

    @Remark("重新启动容器")
    public void restart() {
        renderAPI(containerService.reStart(getClientKey(), getPara("container_id")));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2021/01/12 012 10:46
     */
    @Remark("创建容器")
    public void save() {
        renderAPI(containerService.save(getBean(ContainerBean.class, ""), getClientKey(), getUserId()));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2021/01/12 012 10:58
     */
    @Remark("删除容器")
    public void remove() {
        renderAPI(containerService.remove(getPara("token"), getPara("server_id"), getPara("container_id"), getPara("container_name"), getUserId()));
    }

    /**
     * @Param:
     * @return: TODO
     * @Author: ldl
     * @Create: 2021/01/12 012 11:29
     */
    @Remark("创建信息")
    public void cmd() {
        renderAPISuccess(containerService.cmd(getPara("server_id"), getPara("container_name")));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2021/01/20 020 09:26
     */
    @Remark("创建详情")
    public void detail() {
        Okv cond = Okv.create()
                .set("c.cr_id = ", getPara("cr_id"));
        renderAPISuccess(containerService.detail(Okv.by("cond", cond)));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2021/01/12 012 16:24
     */
    @Remark("下拉列表")
    public void look() {
        Okv cond = Okv.create()
//                .set("c.status_flag = ", "1")
                .set("s.status_flag = ", "1");
        renderAPISuccess(containerService.look(Okv.by("cond", cond)));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2021/01/22 022 09:29
     */
    @Remark("控制台")
    public void console() {
        //只做前端权限判断，不做逻辑处理
        renderAPI(true);
    }

}
